package com.restaurant.application.minifacade.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;
import java.util.List;
import java.util.stream.Collectors;

public class GoodsListBO implements PickableBean {
    
    public static final String FN_LISTS = "lists";
    
    public static final List<String> FIELD_NAMES = Lists.newArrayList(
             FN_LISTS);
    
    private List<GoodsBO> lists;
    
    public GoodsListBO(List<GoodsBO> lists) {
        setLists(lists);
    }
    
    public GoodsListBO() {
    }
    
    public GoodsListBO duplicate() {
        GoodsListBO result = new GoodsListBO();
        result.lists = this.lists == null ? null : this.lists.stream().map(e1->e1 == null ? null : e1.duplicate()).collect(Collectors.toList());
        return result;
    }
    
    @Override
    public String toString() {
        return Convert.toJson(this);
    }
    
    public List<GoodsBO> getLists() {
        if( lists == null) {
            lists = Lists.newArrayList();
        }
        return lists;
    }
    
    public void  setLists(List<GoodsBO> value) {
        this.lists = value;
    }
    
    public GoodsListBO withLists(List<GoodsBO> value) {
        setLists(value);
        return this;
    }
    
    public GoodsListBO withLists(List<GoodsBO> value, List<GoodsBO> defaultValue) {
        setLists(value == null ? defaultValue : value);
        return this;
    }
    
    public GoodsListBO addLists(GoodsBO value) {
        if(lists == null) {
            lists = Lists.newArrayList();
        }
        this.lists.add(value);
        return this;
    }
    
    public Object getValueOf(String name) {
        switch(name) {
        case "lists": return getLists();
        }
        return null;
    }
    
    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }
    
    @Override
    public int hashCode() {
        return signature().hashCode();
    }
    
    @Override
    public boolean equals(Object o) {
        if(!(o instanceof GoodsListBO)) return false;
        return signature().equals(((GoodsListBO)o).signature());
    }
    
    public String signature() {
        throw new RuntimeException("Bean GoodsListBO has no signature defined, no hash code or equals possible.");
    }
}
